home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
utility
/
speed_3.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
7KB
|
165 lines
; Program Name: SPEED_3.S
; Version 1.004
; NOTE: This program is similar to SPEED_2. The differences are that a
; different algorithm is used to process the command line, and no user
; stack is declared in SPEED_3.
; Assembly Instructions:
; Assemble in "PC-relative" mode and save with a TTP extension.
; Function:
; Spawn a process and calculate the spawned program's load and execution
; times. Pause for a keypress before terminating.
release_excess_memory:
lea program_end, a0 ; Put "end of program" address in A0.
movea.l 4(a7), a1 ; Put "basepage" address in A1.
lea $80(a1), a3 ; Put "command line" address in A3.
trap #6 ; Calculate program size and release memory.
; NOTE: A local stack is not declared in PRG_5AP.TOS. Because of the long
; string that is printed by that program, this program will bomb when
; it spawns PRG_5AP.TOS, if a local stack is not declared here.
lea stack, a7 ; Point A7 to this program's stack.
; COMMAND LINE PROCESSING NOTE
; At this point register A3 contains the address of the command line.
; In the algorithm below, the address of the first ASCII character in the
; command line input is stored at the pointer "program_name". Then a NULL
; character is written over the carriage return code at the end of the
; command line input. Thus the command line input itself becomes the
; string, the address of which must be pushed on the stack during the p_exec
; invocation.
; Even though register A3 contains the address of the program name string,
; and the contents of A3 can be pushed during the p_exec invocation, the
; address of the string must be stored in a declared location because
; register A3 might be used by the spawned program. And the address of the
; string is still needed to print the spawned program's name in SPEED_3's
; output heading.
process_command_line:
lea command_line, a4 ; Fetch location to contain command line.
movem.l (a3), d0-d3 ; Move 16 bytes of command line to 4 registers.
movem.l d0-d3, (a4) ; Move them to address "command_line".
move.b (a3)+, d0 ; Fetch parameter line input character count.
ext.w d0 ; Extend to word for next instruction.
move.b #0, 1(a4,d0.w) ; Store a null at end of string.
lea program_name, a0 ; Fetch address of pointer to program name.
move.l a3, (a0) ; Store address of program name in pointer.
move.b #0, 0(a3,d0.w) ; Replace $0D at end of program name with NULL.
insert_filename_suffix:
move.b #$44, -2(a4,d0.w) ; Insert letter 'D'.
move.b #$41, -1(a4,d0.w) ; Insert letter 'A'.
move.b #$54, 0(a4,d0.w) ; Insert letter 'T'.
create_file:
move.w #0, -(sp) ; File attribute = read/write.
pea filename ; Will be name of spawned process + .DAT.
move.w #$3C, -(sp) ; Function = f_create = GEMDOS $3C.
trap #1 ; File handle is returned in D0.
addq.l #8, sp
lea file_handle, a0
move.w d0, (a0)
redirect_output: ; Exchange file handle with screen's handle.
move.w file_handle, -(sp) ; This is the disk file's handle.
move.w #1, -(sp) ; This is the video screen's handle.
move.w #$46, -(sp) ; Function = f_force = GEMDOS $46.
trap #1
addq.l #6, sp
prepare_stack_for_load_and_execute_program:
pea environ_string
pea command_string
pea (a3) ; Push address of program name string.
move.w #0, -(sp)
move.w #$4B, -(sp) ; Function = GEMDOS $4B = p_exec.
get_start_time:
lea start_time, a3 ; Fetch address of variable "start_time".
trap #3 ; Returns value of system clock in D0.
move.w d0, (a3) ; Save start time.
load_and_execute_program:
trap #1
move.w d0, d3 ; Copy after-load value to D3 for calculation.
get_end_time:
trap #3 ; Returns value of system clock in D0.
move.w d0, d5 ; Copy to D5 for calculation.
sub.w d3, d5 ; Subtract after-load time from end time.
ext.l d5 ; Extend to 32 bits.
reposition_stack_pointer:
lea $10(sp), sp
get_drive:
move.w #$19, -(sp) ; Function = dgetdrv = GEMDOS $19.
trap #1
addq.l #2, sp
add.b #'A', d0
lea drive, a0
move.b d0, (a0)
print_heading:
lea heading, a0
bsr print_string
lea program_name, a0 ; Fetch address of program name string.
movea.l (a0), a0
bsr print_string ; Print spawned program's name.
print_drive_for_spawned_program:
lea drive_msg, a0 ; Print drive from which spawned program was
bsr print_string ; loaded.
compute_load_time:
lea load_time_msg, a0
bsr print_string
lea start_time, a3
sub.w (a3), d3 ; Subtract start time from after-load time.
ext.l d3 ; Extent to 32 bits.
trap #9 ; See description in TRAPS.S.
close_file:
move.w file_handle, -(sp)
move.w #$3E, -(sp) ; Function = fclose = GEMDOS $3E.
trap #1
addq.l #4, sp
terminate:
move.w #0, -(sp)
trap #1
print_string: ; Expects address of string to be in A0.
move.l a0, -(sp) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
heading: dc.b $D,$A,"SPEED_3.TTP Execution Results",$D,$A
dc.b "for ",0
drive_msg: dc.b ", loaded from drive: "
drive: dc.b "A",$D,$A,0
load_time_msg: dc.b $D,$A," Load time: ",0
environ_string: dc.b "TERM",0
command_string: dc.b 0
align
bss
start_time: ds.w 1
program_name: ds.l 1 ; Pointer to string in basepage command line.
file_handle: ds.w 1
command_line: ds.b 1 ; Unused character count will go here.
filename: ds.b 15 ; File name for redirected output.
ds.l 96 ; Program stack.
stack: ds.l 0 ; Address of program stack.
program_end: ds.l 0
end